/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package it.evento.webservices;

import it.evento.BusinessLogic;
import it.evento.Events;
import it.evento.EventsList;
import it.evento.EventtypesList;
import it.evento.LocationsList;
import it.evento.Users;
import java.util.List;
import javax.ejb.EJB;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;

import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonArrayBuilder;
import javax.json.JsonBuilderFactory;
import javax.json.JsonObjectBuilder;

/**
 *
 * @author Mark
 */
@WebService(serviceName = "EvenToWS")
@Stateless()
public class EvenToWS {
    @EJB
    private BusinessLogic businessLogic;
    
    private final JsonBuilderFactory factory = Json.createBuilderFactory(null);
    JsonArrayBuilder jaBuild = factory.createArrayBuilder();
    JsonObjectBuilder joBuild = factory.createObjectBuilder();
    /**
     * This is a sample web service operation
     */
    @WebMethod(operationName = "hello")
    //public String hello(@WebParam(name = "name") String txt) {
    public String hello() {
        //return "Hello " + txt + " !";
        return "Hello, you are connected to EvenTo Application!";
    }

    /**
     * Web service operation
     */
    /*
    @WebMethod(operationName = "getAllEvents")
    public String getAllEvents(){
        System.out.println("businessLogic: "+businessLogic);
        List<Events> events_list = businessLogic.getAllEvents();
        System.out.println("events_list: "+events_list);
        for(Events e:events_list){
            joBuild.add("id",e.getId());
            joBuild.add("label",e.getName());

            jaBuild.add(joBuild);
        }
        String out=jaBuild.build().toString();
        System.out.println(out);
        return out;           
    }
    */
    /**
     * Web service operation
     */
    /*
    @WebMethod(operationName = "getAllUsers")
    public List<Users> getAllUsers() {
         
        return  businessLogic.getAllUsers();
    }
    */

    /**
     * Web service operation
     */
    
    @WebMethod(operationName = "getAllEvents")
    public EventsList getAllEvents() {        
        EventsList evl = new EventsList();
        evl.setEventsList(businessLogic.getAllEvents());
        return evl;
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "getAllLocations")
    public LocationsList getAllLocations() {
        LocationsList locList= new LocationsList();
        locList.setLocationList(businessLogic.getAllLocations());
        return locList;
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "getAllEventtyes")
    public it.evento.EventtypesList getAllEventtyes() {
        EventtypesList evtypesList=new EventtypesList();
        evtypesList.setEventtypesList(businessLogic.getAllEventTypes());
        return evtypesList;
    }

}
